﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ecopsy.Tools;
using AgencyEntityLib.BaseEntity;

public partial class iFarmeAdmin_DictionaryList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            MyDataBind ();
        }
    }

    public TreeDictionaryTypeList_Item[] GetList(int startRowIndex, int maximumRows, out int RowCount)
    {

        TreeDictionaryTypeList l = new TreeDictionaryTypeList();
        l.Load();
        List<TreeDictionaryTypeList_Item> ll = new List<TreeDictionaryTypeList_Item>();
        foreach (TreeDictionaryTypeList_Item item in l)
        {
            if (AgencyID == "" && item.IsSystem != 0) ll.Add(item);
            if (AgencyID != "" && item.IsSystem == 0) ll.Add(item); 
        }
        TreeDictionaryTypeList_Item[] r = ll.ToArray<TreeDictionaryTypeList_Item>();        
        RowCount = l.Count ;
        return r;
    }

    private void MyDataBind()
    {
        ObjectDS_PF ODS = new ObjectDS_PF(GetList);
        lvDictionaryList.DataSource = ODS.ImAsObjectDataSource;
        DataBind();

    }
    protected void onEditDictionary(object sender, EventArgs e)
    {
        string s = ((LinkButton)sender).CommandArgument;
        string f = (AgencyID == String.Empty ? GlobalConstants.TreeDictionaryFolderType_System : AgencyID);
        
        if (s == GlobalConstants.TreeDictionary_AdressProgram)
        {
            Response.Redirect("iFarmeDictionary_AdressPrograms.aspx");

        }
        
        Response.Redirect("iFarmeDictionary_TreeDictonary.aspx?TreeDictionaryID=" + s + "&FolderID=" + f);
    }

    protected string AgencyID { get { return Request.QueryString["AgencyID"]; } }
}
